package com.web.config;

import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.web.controller.*;
import com.web.model.*;

/**
 * Created by hoaran on 2015/7/3.
 */
public class JfinalConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true); //设置开发者模式为开
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/user", UserController.class); // 把"/user"开始的请求映射到UserController上
        me.add("/page", PageController.class); // 把"/page"开始的请求映射到PageController上
        me.add("/upload", UploadController.class); // 把"/upload"开始的请求映射到UploadController上
        me.add("/edit",EditController.class); // 把"/edit"开始的请求映射到EditController上
        me.add("/recom",RecomController.class); // 把"/recom"开始的请求映射到RecomController上
        me.add("/crontab",CrontabController.class); // 把"/crontab"开始的请求映射到CrontabController上
        me.add("/mobile",MobileController.class);
    }


    @Override
    public void configPlugin(Plugins me) {
        /**
         * 使用 C3P0 连接池管理数据库连接
         */

        //TODO:数据库使用的是本地数据库，做测试用
//        C3p0Plugin c3p0Plugin = new C3p0Plugin("jdbc:mysql://rdse5ureq44zwrp74g4y.mysql.rds.aliyuncs.com:3306/kuibusoftware", "haoransun",
//                "haoransunjiushidiao123");
//        C3p0Plugin c3p0Plugin = new C3p0Plugin("jdbc:mysql://rdse5ureq44zwrp74g4y.mysql.rds.aliyuncs.com:3306/kuibuapp", "haoransun",
//                "haoransunjiushidiao123");
        C3p0Plugin c3p0Plugin = new C3p0Plugin("jdbc:mysql://localhost:3306/kuibusoftware", "root",
                "Kuibureeves52155");
        me.add(c3p0Plugin);
        /**
         * 使用 ActiveRecord 操作数据库
         */
        ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(c3p0Plugin);
        me.add(activeRecordPlugin);

        activeRecordPlugin.addMapping("com_userinfo", "id", User.class);
        activeRecordPlugin.addMapping("page_titleimage", "imageId", PageTitleImage.class);
        activeRecordPlugin.addMapping("page_edit", "id", PageEdit.class);
        activeRecordPlugin.addMapping("page_info","pageId",PageInfo.class);
        activeRecordPlugin.addMapping("type_info",TypeInfo.class);
    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

    }
}
